package com.sniff.atp.modules.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sniff.atp.modules.test.mapper.PlatformAddressMapper;
import com.sniff.atp.modules.test.model.PlatformAddress;
import com.sniff.atp.modules.test.service.PlatformAddressService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.modules.test.service.impl
 * @Author: zxy
 * @CreateTime: 2024-01-23 16:49
 * @Description:
 * @Version: 1.0
 */
@Service
public class PlatformAddressServiceImpl extends ServiceImpl<PlatformAddressMapper, PlatformAddress> implements PlatformAddressService {
    @Override
    public boolean create(PlatformAddress platformAddress) {
        platformAddress.setCreateTime(new Date());
        platformAddress.setUpdateTime(new Date());
        return save(platformAddress);
    }

    @Override
    public boolean update(Long id, PlatformAddress platformAddress) {
        platformAddress.setId(id);
        platformAddress.setUpdateTime(new Date());
        return updateById(platformAddress);
    }

    @Override
    public boolean delete(Long id) {
        return this.removeById(id);
    }

    @Override
    public Page<PlatformAddress> list(PlatformAddress platformAddress, Integer pageSize, Integer pageNum) {

        Page<PlatformAddress> page = new Page<>(pageNum, pageSize);
        QueryWrapper<PlatformAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(PlatformAddress::getCreateTime);

        return page(page, queryWrapper);
    }

}
